#include "systemsettingdialog.h"
#include "ui_systemsettingdialog.h"
#include "settingsdialog.h"
#include <QSettings>

SystemSettingDialog::SystemSettingDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SystemSettingDialog)
{
    ui->setupUi(this);

    connect(ui->applyButton, SIGNAL(clicked()),this, SLOT(applyIni()));
    connect(ui->cancleButton, SIGNAL(clicked()),this, SLOT(cancle()));
    connect(ui->serialBtn, SIGNAL(clicked()), this, SLOT(serialSetting()));
    settings=new SettingsDialog;

}

SystemSettingDialog::~SystemSettingDialog()
{
    delete ui;
}

void SystemSettingDialog::applyIni()
{
    QSettings settingsIni("/home/EPOS.ini", QSettings::IniFormat);
    settingsIni.beginGroup("machine");
    settingsIni.setValue("id",ui->idLineEdit->text());
    settingsIni.endGroup();
    settingsIni.beginGroup("server");
    settingsIni.setValue("serveruri", ui->serverLineEdit->text());
    settingsIni.setValue("serverport", ui->portLineEdit->text());
    settingsIni.endGroup();

    /**
    SettingsDialog::Settings p = settings->settings();
    settingsIni.beginGroup("serialport");
    settingsIni.setValue("PortName",p.name);
    settingsIni.setValue("BaudRate", p.baudRate);
    settingsIni.setValue("DataBits", (int)p.dataBits);
    settingsIni.setValue("Parity", (int)p.parity);
    settingsIni.setValue("StopBits",(int)p.stopBits);
    settingsIni.setValue("FlowControl", (int)p.flowControl);

    settingsIni.endGroup();**/

    settingsIni.sync();
}
void SystemSettingDialog::cancle()
{
    this->hide();
}
void SystemSettingDialog::serialSetting()
{
    settings->show();
}

